# -*- coding: utf-8 -*-
"""
@Time : 2024/1/10 14:06
@Author : TJF

"""
import datetime
import time
import json
from selenium.webdriver.common.by import By


# write your function this file
def today():
	now = datetime.datetime.now()
	return now.strftime('%Y%m%d')

def get_token(pro_name):
	from seleniumwire import webdriver

	# global result
	options = webdriver.ChromeOptions()
	options.add_argument('--headless')
	driver = webdriver.Chrome(options=options)
	if pro_name == 'Geely_api_test':
		# 启动Chrome浏览器，将chrome_options和seleniumwire_options传递进去
		driver.get('http://106.75.247.11:18887/app/eventManagement')
		time.sleep(5)
		user = driver.find_element(By.NAME, 'username')
		passw = driver.find_element(By.NAME, 'password')
		user.send_keys("admin")
		passw.send_keys("Exceed!Amk@vpo#")
		driver.find_element(By.NAME, 'login').click()
		time.sleep(5)
	try:
		for req in driver.requests:
			if req.url.endswith("token"):
				result = json.loads(req.response.body)
				print(result["access_token"])
	finally:
		driver.close()
	return result["access_token"]


# if __name__ == '__main__':
# # 	# print(get_token('http://106.75.247.11:18887/app/eventManagement', 'admin', 'Exceed!Amk@vpo#', 'token', 'access_token'))
# 	get_token("Geely_api_test")
